package hua.mtreader.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * Created by Administrator on 2017/3/14.
 */

public abstract class BaseFragment<V,T extends BaseFragmentPresenter<V>> extends Fragment {


    public Context mContext;
    public View view;
    public T mPresenter;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getActivity();
        mPresenter = createPresenter();
        mPresenter.attachView((V)this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mPresenter.detachView();
    }

    public abstract T createPresenter();


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = initView();
        initData();
        setListener();
        return view;
    }

    public abstract View initView();
    public abstract void initData();
    protected abstract void setListener();


    @Override
    public void setMenuVisibility(boolean menuVisible) {
        if (view != null) {
            view.setVisibility(menuVisible?View.VISIBLE:View.GONE);
        }
    }
}
